layui.use(['table', 'admin', 'ax', 'ztree'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var $ZTree = layui.ztree;

    /**
     * 系统管理--参数管理
     */
    var Config = {
        tableId: "subscribeTable",
        condition: {
            configId: ""
        }
    };

    /**
     * 初始化表格的列
     */
    Config.initColumn = function () {
        return [[
            // {type: 'checkbox'},
            {field: 'id', hide: true, sort: true, title: 'id'},
            {field: 'uid', hide: true,sort: true, title: '用户id'},
            {field: 'account', sort: true, title: '申购账号',minWidth:200},
            {field: 'subscription_currency_name', sort: true, title: '申购币种'},
            {field: 'subscription_currency_amount', sort: true, title: '申购数量'},
            {field: 'payment_currency', sort: true, title: '支付币种'},
            {field: 'payment_amount', sort: true, title: '支付数量'},
            {field: 'status', sort: true, title: '状态',width:100,templet: function (data) {
                    switch (data.status) {
                        case '0':
                            return '等待上市'
                            break;
                        default:
                            return '已上市'
                    }}},
            {field: 'subscription_time', sort: true, title: '申购时间'},

            {field: 'lucky_currency_amount', sort: true, title: '中签数量'},
           {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 100}
        ]];
    };

    /**
     * 点击查询按钮
     */
    Config.search = function () {
        var queryData = {};
        queryData['name'] = $("#name").val();
        queryData['account'] = $("#account").val();
        queryData['configId'] = Config.condition.configId;
        table.reload(Config.tableId, {where: queryData});
    };

    /**
     * 选择参数时
     */
    Config.onClickConfig = function (e, treeId, treeNode) {
        Config.condition.configId = treeNode.id;
        Config.search();
    };


    /**
     * 点击编辑参数
     *
     * @param data 点击按钮时候的行数据
     */
    Config.onEditConfig = function (data) {
        admin.putTempData('formOk', false);
        top.layui.admin.open({
            type: 2,
            title: '修改参数',
            area:["1080px","400px"],
            content: Feng.ctxPath + '/subscribe/records_edit?id=' + data.records_id,
            end: function () {
                admin.getTempData('formOk') && table.reload(Config.tableId);
            }
        });
    };


    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Config.tableId,
        url: Feng.ctxPath + '/subscribe/recordslist',
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        limit:100,
        limits: [100,200,300,400,500],
        cols: Config.initColumn()
    });
    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Config.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        Config.openAddConfig();
    });

    // 导出excel
    $('#btnExp').click(function () {
        Config.exportExcel();
    });

    // 工具条点击事件
    table.on('tool(' + Config.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'edit') {
            Config.onEditConfig(data);
        } else if (layEvent === 'delete') {
            Config.onDeleteConfig(data);
        }
    });
});
